﻿@{
    ViewData["Title"] = "Home Page";
}
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta content="initial-scale=1.0,user-scalable=no,maximum-scale=1,width=device-width" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection" />
    <link type="text/css" href="css/reg.css" rel="stylesheet" />
    <title>登录</title>
</head>

<body>
    <div class="baicaojiMain">
        <div class="baicaojiLogo"></div>
        <div class="acc-login-input baicaoji-loginbox">
            <ul class="inputCss">
                <li style="display:none" id="user"><p class="user"><span><input name="nick" type="text" placeholder="请输入用户名" maxlength="20" class="txt"></span><em></em></p></li>
                <li><p><span><input name="email" id="mail" type="tel" placeholder="请输入邮箱" maxlength="20" class="txt"></span><em></em></p></li>

                <li style="display:none" id="code"><p><span><input name="mailcode" id="mailcode" type="tel" placeholder="请输入邮箱验证码" maxlength="20" class="txt"></span><div class="registerBtn" id="send">发送验证码</div></p></li>

                <li><p class="password"><span><input name="password" type="password" placeholder="请输入密码" maxlength="20" class="txt"></span><em></em></p></li>

                <li style="display:none" id="agepass"><p class="passwordage"><span><input name="passwordage" type="password" placeholder="请再次输入密码" maxlength="20" class="txt"></span><em></em></p></li>

            </ul>
            <div class="submitBtn">登录</div>
            <div class="registerBtn" id="registerBtn">注册</div>
        </div>
    </div>


</body>
</html>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
    var patrn = /^0?(13[0-9]|15[0-9]|17[0-9]|18[0-9]|14[0-9])[0-9]{8}$/;
    var tipsflag = true;
    function tips(text) {
        if (tipsflag == true) {
            var tishiDiv = document.createElement('div');
            tishiDiv.className = "motify";
            document.body.appendChild(tishiDiv);
            tipsflag = false;
        }
        $('.motify').html(text).show();
        setTimeout(function () { $('.motify').fadeOut(); }, 500);
    }

    var num = 60;
    var timerrr;
    var flag = true, flaglogin = true;
    var daojishi = document.getElementById('timeid');
    function dao() {
        if (num > 0) {
            num -= 1;
            daojishi.innerHTML = num;
            if (num < 10) {
                daojishi.innerHTML = "0" + num;
            }
        }
        if (num == 0) {
            daojishi.innerHTML = "获取验证码";
            num = 60;
            daojishi.className = 'yanzhengma';
            flag = true;
            clearInterval(timerrr);
        }

    }
    function isPhone(phone) {
        var myreg = /^0?(13[0-9]|15[0-9]|17[0-9]|18[0-9]|14[0-9])[0-9]{8}$/;;
        if (!myreg.test(phone)) return false;
        return true;
    }

    $("input[name=nick]").bind('input propertychange', function () {
        $(this).parent().next().hide();
    })
    $("input[name=password]").bind('input propertychange', function () {
        $(this).parent().next().hide();
    })


    $("input[name=phone]").bind('input propertychange', function () {
        $('#timeid').removeClass('opacityBtn');
        $(this).parent().next().hide();
        $("#timeid").click(function () {
            var phone = $('input[name=phone]').val()
            if (phone != '') {
                if (isPhone(phone)) {
                    if (flag == true) {
                        daojishi.className = 'yanzhenghui';
                        dao();
                        timerrr = setInterval('dao()', 1000);
                        tips("验证码已发送");
                        flag = false;
                    }
                } else {
                    tips("请输入正确的手机号码");
                    $("input[name=phone]").parent().next().show();
                }
            } else {
                tips("请输入手机号码");
                $("input[name=phone]").parent().next().show();
            }
        })
    });

    $("#send").click(function () { 
        var email = $('input[name=email]').val();
        $.ajax({
            url: "/Home/SendEmail",
            data: { email: email },
            method: "post",
            success: function (data) {
                flaglogin = true;
                if (data.status == "1") {
                    tips("成功！");
                } else {
                    tips(data.msg);
                }
            }
        })
    })

    $("#mail").blur(function () {
        tips("当失去焦点友好提示是否有该用户(异步查询数据库)，功能就不实现了。");
    })

    var isok = false;

    $("#registerBtn").click(function () {

        if (isok) {
            var password = $('input[name=password]').val();
            var email = $('input[name=email]').val();
            var passwordage = $('input[name=passwordage]').val();
            var nick = $('input[name=nick]').val();
            var mailcode = $('input[name=mailcode]').val();

            if (password != passwordage) {
                tips("两次输入密码不一样！");
                return false;
            }
            var reg = /\w+[@@]{1}\w+[.]\w+/;
            if (!reg.test(email)) {
                tips("邮箱格式不正确！");
                return false;
            }

            $.ajax({
                url: "/Home/RegisterMember",
                method: "post",
                data: { password: password, email: email, nick: nick, code: mailcode },
                success: function (data) {
                    tips(data.msg);
                }

            })
        } else {
            $("#user").show();
            $("#agepass").show();
            $("#code").show();
            $(".submitBtn").hide();
            isok = true;
        }

    })

    $(".submitBtn").click(function () {
        var password = $('input[name=password]').val();
        var email = $('input[name=email]').val();


        if (!password) {
            $("input[name=password]").parent().next().show();
            return false;
        }

        var reg = /\w+[@@]{1}\w+[.]\w+/;
        if (!reg.test(email)) {
            tips("邮箱格式不正确！");
            return false;
        }

        if (flaglogin == true) {
            flaglogin = false;
            $.ajax({
                url: "/Home/ToLogin",
                data: { email: email, password: password },
                method: "post",
                success: function (data) {
                    flaglogin = true;
                    if (data.status == "1") {
                        tips("成功！");
                    } else {
                        tips(data.msg);
                    }
                }
            })
        } else {
            tips("请不要重复点击！");
        }
    })
</script>
